package com.axc.system.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axc.system.domain.CommonreportstatisticsDO;
import com.axc.system.service.CommonreportstatisticsService;
import com.axc.common.annotation.Log;
import com.axc.common.utils.PageLayUi;
import com.axc.base.controller.BaseController;
import com.axc.common.utils.PageUtils;
import com.axc.common.utils.Query;
import com.axc.common.utils.R;

/**
 * ${comments}
 * 
 * @author admin
 * @email yfq900108@163.COM
 * @date 2018-12-25 21:05:55
 */

@Controller
@RequestMapping("/system/commonreportstatistics")
public class CommonreportstatisticsController extends BaseController {

	// 添加日志模块
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private CommonreportstatisticsService commonreportstatisticsService;

	@GetMapping()
	@RequiresPermissions("system:commonreportstatistics:commonreportstatistics")
	String Commonreportstatistics(String Type) {
		String ret = "system/commonreportstatistics/commonreportstatistics";
		if (Type != null) {

			ret = "system/commonreportstatistics/EmissionFactor";
		}

		return ret;
	}

	@Log("请求访问主页")
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:commonreportstatistics:commonreportstatistics")
	public PageUtils list(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);
		List<CommonreportstatisticsDO> commonreportstatisticsList = commonreportstatisticsService.list(query);
		int total = commonreportstatisticsService.count(query);
		PageUtils pageUtils = new PageUtils(commonreportstatisticsList, total);
		return pageUtils;
	}

	@Log("请求访问报表详情页面")
	@ResponseBody
	@GetMapping("/listReport")
	@RequiresPermissions("system:commonreportstatistics:commonreportstatistics")
	public List<LinkedHashMap<String, Object>> listReport(String sqlContent) {
		// 查询报表详情

		Map<String, Object> query = new HashMap<>(16);
		query.put("computerTsql", sqlContent);
		List<LinkedHashMap<String, Object>> commonreportstatisticsList = commonreportstatisticsService
				.listReport(query);

		return commonreportstatisticsList;
	}

	@Log("浏览报表详情页面")
	@ResponseBody
	@GetMapping("/getReport")
	public List<LinkedHashMap<String, Object>> getReport(String sid, String StartTime, String EndTime,
			Boolean HistoryOrNo) {
		// 查询报表详情
		CommonreportstatisticsDO commonreportstatistics = commonreportstatisticsService.get(sid);

		Map<String, Object> query = new HashMap<>(16);
		query.put("computerTsql", commonreportstatistics.getComputerTsql());
		List<LinkedHashMap<String, Object>> commonreportstatisticsList = commonreportstatisticsService
				.listReport(query);

		return commonreportstatisticsList;
	}

	/**
	 * 新增页面，无需传值
	 */
	@Log("请求统计页面")
	@GetMapping("/report")
	@RequiresPermissions("system:commonreportstatistics:report")
	String report() {
		return "system/commonreportstatistics/EmissionFactor";
	}

	/**
	 * 新增页面，无需传值
	 */
	@Log("请求新增页面")
	@GetMapping("/add")
	@RequiresPermissions("system:commonreportstatistics:add")
	String add() {
		return "system/commonreportstatistics/add";
	}

	@Log("请求编辑页面")
	@GetMapping("/edit/{sid}")
	@RequiresPermissions("system:commonreportstatistics:edit")
	String edit(@PathVariable("sid") String sid, Model model) {
		CommonreportstatisticsDO commonreportstatistics = commonreportstatisticsService.get(sid);
		model.addAttribute("commonreportstatistics", commonreportstatistics);
		return "system/commonreportstatistics/edit";
	}

	/**
	 * 保存
	 */
	@Log("新增保存操作")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:commonreportstatistics:add")
	public R save(CommonreportstatisticsDO commonreportstatistics) {

		commonreportstatistics.setCreatedate(new Date());
		if (commonreportstatisticsService.save(commonreportstatistics) > 0) {
			return R.ok();
		}
		return R.error();
	}

	/**
	 * 修改
	 */
	@Log("修改保存操作")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:commonreportstatistics:edit")
	public R update(CommonreportstatisticsDO commonreportstatistics) {
		commonreportstatisticsService.update(commonreportstatistics);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@Log("列表删除页面数据")
	@PostMapping("/remove")
	@ResponseBody
	@RequiresPermissions("system:commonreportstatistics:remove")
	public R remove(String sid) {
		if (commonreportstatisticsService.remove(sid) > 0) {
			return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@Log("按钮删除页面数据")
	@PostMapping("/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:commonreportstatistics:batchRemove")
	public R remove(@RequestParam("ids[]") String[] sids) {
		commonreportstatisticsService.batchRemove(sids);
		return R.ok();
	}

	/*
	 * 统计图表 报表 名称
	 */
	@ResponseBody
	@GetMapping("/listAllName")
	public List<LinkedHashMap<String, Object>> list_by_code(String type) {
		Map<String, Object> query = new HashMap<>(16);
		query.put("computerTsql", "select SID,SNAME from COMMONREPORTSTATISTICS where stype=" + type);

		List<LinkedHashMap<String, Object>> commonreportstatisticsList = commonreportstatisticsService
				.listReport(query);
		// List<LinkedHashMap<String, Object>> commonreportstatisticsList =
		// commonreportstatisticsService.listReport(query);
		return commonreportstatisticsList;
	}

	/**
	 * 列表页面
	 */
	@Log("请求列表页面 ")
	@GetMapping("/listPager")

	String listPager(String sid, Model model) {

		if (sid != null && sid != "") {
			CommonreportstatisticsDO commonreportstatistics = commonreportstatisticsService.get(sid);
			model.addAttribute("commonreportstatistics", commonreportstatistics);
		}
		return "system/commonreportstatistics/listPager";
	}
	
	
	@Log("请求列表页面 ")
	@GetMapping("/EmissionFactor")

	String EmissionFactor() {

		
		return "system/commonreportstatistics/listPager";
	}
	

	/**
	 * 新增页面
	 */
	@Log("请求新增页面带参数 ")
	@GetMapping("/addModel")
	@RequiresPermissions("system:commonreportstatistics:add")
	String addModel() {
		return "system/commonreportstatistics/addModel";
	}

	@Log("请求编辑页面")
	@GetMapping("/editModel")
	@RequiresPermissions("system:commonreportstatistics:edit")
	String editModel(String sid, Model model) {
		CommonreportstatisticsDO commonreportstatistics = commonreportstatisticsService.get(sid);
		model.addAttribute("commonreportstatistics", commonreportstatistics);
		return "system/commonreportstatistics/editModel";
	}

	/**
	 * LayUi 分页查询
	 */
	@Log("请求LayUi页面 ")
	@ResponseBody
	@GetMapping("/PageLayUi_List_By_Query")
	@RequiresPermissions("system:commonreportstatistics:PageLayUi_List_By_Query")
	public PageLayUi<CommonreportstatisticsDO> PageLayUi_List_By_Query(CommonreportstatisticsDO query) {

		List<CommonreportstatisticsDO> dataList = commonreportstatisticsService.PageLayUi_List_By_Query(query);
		int total = commonreportstatisticsService.total(query);
		PageLayUi<CommonreportstatisticsDO> pageLayUi = new PageLayUi<CommonreportstatisticsDO>(0, "", total, dataList);
		return pageLayUi;
	}

	/**
	 * 根据query ，查询并返回一条记录
	 */
	@Log("请求查询页面，传参 ")
	@ResponseBody
	@GetMapping("/Get_Model_By_Query")
	@RequiresPermissions("system:commonreportstatistics:Get_Model_By_Query")
	public CommonreportstatisticsDO Get_Model_By_Query(CommonreportstatisticsDO query) {
		CommonreportstatisticsDO model = commonreportstatisticsService.Get_Model_By_Query(query);
		return model;
	}

}
